//
//  SEGUpdateAppView.m
//  ExcellentHome
//
//  Created by 揭婧雯 on 2017/12/5.
//  Copyright © 2017年 陈区. All rights reserved.
//

#import "SEGUpdateAppView.h"

@implementation SEGUpdateAppView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self customUI];
    }
    return self;
}

- (void)customUI
{
    self.backgroundColor = kColor_bg3;
    
    UIView *centerView = [[UIView alloc] init];
    [self addSubview:centerView];
    [centerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self);
        make.width.mas_equalTo(310.0);
    }];
        
    UIButton *closeButton = [[UIButton alloc] init];
    [closeButton setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"icon_pop_close")] forState:UIControlStateNormal];
    [closeButton addTarget:self action:@selector(closeButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    [centerView addSubview:closeButton];
    [closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(centerView);
        make.right.equalTo(centerView).offset(-5);
    }];
    self.closeButton = closeButton;
    
    UIImageView *topImageView = [[UIImageView alloc] init];
    topImageView.image = [UIImage imageWithContentsOfFile:SEGPicName(@"pic_pop")];
    [centerView addSubview:topImageView];
    [topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(centerView).offset(17);
        make.centerX.equalTo(centerView);
    }];

    //中间白色背景
    UIView *whiteView = [[UIView alloc] init];
    whiteView.backgroundColor = UIColor.whiteColor;
    whiteView.layer.masksToBounds = YES;
    whiteView.layer.cornerRadius = 5;
    [centerView addSubview:whiteView];
    [whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topImageView.mas_bottom).offset(-5);//解决上半部分的圆角暴露出来的问题
        make.centerX.equalTo(centerView);
        make.width.equalTo(centerView);
        make.bottom.equalTo(centerView);
    }];
    [centerView bringSubviewToFront:topImageView];
    
    UILabel *contentLabel = [[UILabel alloc] init];
    contentLabel.font = kFont_15;
    contentLabel.textColor = [UIColor colorWithHexString:@"#333333"];
    contentLabel.numberOfLines = 0;
    [whiteView addSubview:contentLabel];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(whiteView).offset(15);
        make.right.equalTo(whiteView).offset(-15);
        make.top.equalTo(whiteView.mas_top).offset(34);
    }];
    self.contentLabel = contentLabel;
    
    UIButton *updateButton = [[UIButton alloc] init];
    [updateButton setTitle:@"立即更新" forState:UIControlStateNormal];
    [updateButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    updateButton.titleLabel.font = kFont_16;
    [updateButton setBackgroundImage:[UIImage imageWithContentsOfFile:SEGPicName(@"btn_pop_nor")] forState:UIControlStateNormal];
    [whiteView addSubview:updateButton];
    [updateButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(whiteView);
        make.top.equalTo(contentLabel.mas_bottom).offset(29);
        make.width.mas_equalTo(145.0);
        make.height.mas_equalTo(35.0);
        make.bottom.equalTo(whiteView.mas_bottom).offset(-30.0);
    }];
    self.updateButton = updateButton;
}

- (void)closeButtonPressed
{
    [self removeFromSuperview];
}

@end
